    
	var PeopleMedia = PeopleMedia || {};
	
    PeopleMedia.FastActionModule = new function () {
        this.Actions = {};
        this.FAM_NextActionTakenKey = "ClickedNextModule";
        this.FAM_SendBirthdayFlirtKey = "SendBirthdayFlirt";
        this.FAM_NewMemberInAreaKey = "NewMemberInArea";
        this.FAM_LikePhotoKey = "LikePhoto";
        this.FAM_SaveToFavoritesKey = "SaveToFavorites";
        this.FAM_ActionTakenQueue = new Array();
        this.FAM_ActionSkip = 2;
        this.FAM_ActionTaken = 3;
        this.SendCommentUPN = "71";
        this.MaximumMessageLength = 3000;
        this.FeatureName = 'communityupdates';
        this.ThrottleRequest = function (setProgress) {
            // Don't allow the button to be non stop clicked
            if (setProgress == true) {
                PeopleMedia.FastActionModule.FAM_ActionTakenQueue[PeopleMedia.FastActionModule.FAM_ActionTakenQueue.length] = PeopleMedia.FastActionModule.FAM_NextActionTakenKey;
                setTimeout(function () {
                    PeopleMedia.FastActionModule.ThrottleRequest(false);
                }, 2000);
            } else {
                PeopleMedia.FastActionModule.FAM_ActionTakenQueue.splice(PeopleMedia.FastActionModule.FAM_NextActionTakenKey, 1);
            }
            PeopleMedia.FastActionModule.Debug();
        };
        this.Debug = function (info) {
            if (PeopleMedia.FastActionModule.Actions.ShowDebug == true) {
                if (info != null && info.message != null) {
                    $jq("#debugspace").prepend("<br /> <b>status:</b>" + info.status + " <b>message:</b>" + info.message);
                } else if (PeopleMedia.FastActionModule.FAM_ActionTakenQueue.length > 0) {
                    $jq("#debugspace").prepend("<br /> <b>queue size:</b> " + PeopleMedia.FastActionModule.FAM_ActionTakenQueue.length + " detail: " + PeopleMedia.FastActionModule.FAM_ActionTakenQueue);
                }
            }
        };
        this.inProgress = function () {
            if (PeopleMedia.FastActionModule.FAM_ActionTakenQueue.length > 0) return true;
            return false;
        };
        this.Init = function () {
            $jq("#NextUpdatesButton").click(PeopleMedia.FastActionModule.SkipAllAndGetNew);
            
            $jq(".fam_comment").on('keyup change', '.fam_comment', function () {
                var limit = PeopleMedia.FastActionModule.MaximumMessageLength;
                var text = $jq(this).val();
                var chars = text.length;
                if (chars > limit) {
                    var new_text = text.substr(0, limit);
                    $jq(this).val(new_text);
                }
                var remain = limit - chars;
                if (remain <= 0) {
                    PeopleMedia.Popups.LongMessage();
                }
            });

            $jq(".fam_comment").on('click', '.fam_comment', function () {
                if ($jq(".fam_comment").val() == "What do you like about this photo?"
                    || $jq(".fam_comment").val() == "Welcome him to the community"
                    || $jq(".fam_comment").val() == "Welcome her to the community") {
                    $jq(".fam_comment").val('');
                }
            });

            PeopleMedia.FastActionModule.GenerateAllModules();
        };

        this.SkipAllAndGetNew = function () {
            if (!PeopleMedia.FastActionModule.inProgress()) {
                PeopleMedia.FastActionModule.ThrottleRequest(true);
                PeopleMedia.FastActionModule.ClearFastActionModuleDisplay('1', '1', PeopleMedia.FastActionModule.FAM_ActionSkip, 'all');
            }
        };
        this.SkipAndGetNew = function (displayIndex, modPosition, forceSkip) {
            var FAM_Action = PeopleMedia.FastActionModule.FAM_ActionSkip;
            if (forceSkip == true) {
                FAM_Action = PeopleMedia.FastActionModule.FAM_ActionTaken;
            }

            if (!PeopleMedia.FastActionModule.inProgress()) {
                PeopleMedia.FastActionModule.ThrottleRequest(true);
                PeopleMedia.FastActionModule.ClearFastActionModuleDisplay(displayIndex, modPosition, FAM_Action);
            } else if (forceSkip == true) {
                PeopleMedia.FastActionModule.ClearFastActionModuleDisplay(displayIndex, modPosition, FAM_Action);
            }
        };
        this.ClearFastActionModuleDisplay = function (displayIndex, modPosition, FAM_Action, clearAll) {
            var fId = 0;
            if (clearAll == 'all') {
                for (var i = 1; i <= 3; i++) {
                    fId = $jq("#FastActionModule" + i + " .data_fId").text();
                    if (fId > 0) {
                        PeopleMedia.FastActionModule.FAM_ActionTakenQueue[PeopleMedia.FastActionModule.FAM_ActionTakenQueue.length] = fId;
                        PeopleMedia.FastActionModule.ClearModuleData(PeopleMedia.FastActionModule.Actions.DisposeModule, fId, FAM_Action, i, i, PeopleMedia.FastActionModule.Actions.LoadAllModules);
                    }
                }
            } else {
                fId = $jq("#FastActionModule" + displayIndex + " .data_fId").text();
                if (fId > 0) {
                    PeopleMedia.FastActionModule.FAM_ActionTakenQueue[PeopleMedia.FastActionModule.FAM_ActionTakenQueue.length] = fId;
                    PeopleMedia.FastActionModule.ClearModuleData(PeopleMedia.FastActionModule.Actions.DisposeModule, fId, FAM_Action, displayIndex, modPosition, PeopleMedia.FastActionModule.Actions.LoadModule);
                }
            }
            PeopleMedia.FastActionModule.Debug();
        };
        this.GenerateAllModules = function () {
			//(PeopleMedia.FastActionModule.Actions.GenerateAllModules);
			//alert(PeopleMedia.FastActionModule.Actions.GenerateAllModules);
            $jq.ajax({
                type: 'GET',
                cache: false,
                url: PeopleMedia.FastActionModule.Actions.GenerateAllModules,
                success: function (result) {
					//alert('GenerateallModules');
                    PeopleMedia.FastActionModule.Debug(result);
                    $jq("#FastActionModule1").html("");
                    $jq("#FastActionModule2").html("");
                    $jq("#FastActionModule3").html("");
                    PeopleMedia.FastActionModule.GetAllModules();
                }
            });
        };
        this.GetAllModules = function () {
            PeopleMedia.FastActionModule.GetModuleData(PeopleMedia.FastActionModule.Actions.LoadAllModules, 0);
        };
        this.ClearModuleData = function (actionUrl, fId, dId, dIndex, dGroup, loadType, loadtypeDescription) {
            $jq.ajax({
                type: 'GET',
                cache: false,
                url: actionUrl + "?fid=" + fId + "&dId=" + dId + "&dGroup=" + dGroup + "&dIndex=" + dIndex,
                success: function (response) {
                    // remove current queue
                    PeopleMedia.FastActionModule.FAM_ActionTakenQueue.splice(PeopleMedia.FastActionModule.FAM_ActionTakenQueue.indexOf(fId), 1);
                    PeopleMedia.FastActionModule.Debug(response);
                    // once empty (or only click queue), load the next module
                    if (loadtypeDescription == "href") {
                        document.location.href = loadType;
                    }
                    else if (PeopleMedia.FastActionModule.FAM_ActionTakenQueue.length == 0 || PeopleMedia.FastActionModule.FAM_ActionTakenQueue == PeopleMedia.FastActionModule.FAM_NextActionTakenKey) {
                        PeopleMedia.FastActionModule.GetModuleData(loadType + "?dGroup=" + dGroup + "&dIndex=" + dIndex, dIndex);
                    }
                }
            });
        };
        this.DiposeModuleDataOnly = function (actionUrl, fId, dId, dIndex, dGroup) {
            $jq.ajax({
                type: 'GET',
                cache: false,
                url: actionUrl + "?fid=" + fId + "&dId=" + dId + "&dGroup=" + dGroup + "&dIndex=" + dIndex,
                success: function (result) {
                    PeopleMedia.FastActionModule.Debug(result);
                }
            });
        };
        this.GetModuleData = function (actionUrl, dIndex) {
            $jq.ajax({
                type: 'GET',
                cache: false,
                url: actionUrl,
                success: function (result) {
                    PeopleMedia.FastActionModule.Debug(result);
                    PeopleMedia.FastActionModule.SetModuleData(result, dIndex);
                }
            });
        };
        this.TakeAction = function (clickedAction, linkUrl, fId, dIndex, dGroup, memberId, eventScript, encodedMemberId) {
            sourceRecordId = $jq("#FastActionModule" + dIndex + " .data_sourceRecordId").text();
            switch (eventScript) {
                case PeopleMedia.FastActionModule.FAM_LikePhotoKey:
                    $jq("#FastActionModule" + dIndex + " .FAM_LikePhotoHover").hide();
                    actionText = $jq("#FastActionModule" + dIndex + " .FAM_LikePhoto");
                    actionDisplay = $jq("#FastActionModule" + dIndex + " .captionactionplace");
                    actionDisplay.fadeIn("fast");
                    actionText.fadeOut("fast");
                    PeopleMedia.FastActionModule.SendLikePhoto(encodedMemberId, fId, dIndex, dGroup, sourceRecordId);
                    break;
                case PeopleMedia.FastActionModule.FAM_NewMemberInAreaKey:
                    actionText = $jq("#FastActionModule" + dIndex + " .FAM_NewMemberInArea");
                    actionDisplay = $jq("#FastActionModule" + dIndex + " .captionactionplace");
                    if (PeopleMedia.FastActionModule.Actions.LoadPaidModules) {
                        actionDisplay.fadeIn("fast");
                    } else {
                        actionText.css("color", "gray");
                        actionText.css("text-decoration", "none");
                        actionText.text("you said hello");
                        PeopleMedia.FastActionModule.SendFlirt(encodedMemberId, fId, dIndex, dGroup, sourceRecordId);
                    }
                    break;
                case PeopleMedia.FastActionModule.FAM_SaveToFavoritesKey:
                    actionText = $jq("#FastActionModule" + dIndex + " .FAM_SaveAsFavorite");
                    actionText.css("color", "gray");
                    actionText.css("text-decoration", "none");
                    actionText.text("Saved as favorite");
                    PeopleMedia.FastActionModule.SaveToFavorites(encodedMemberId, fId, dIndex, dGroup);
                    break;
                case PeopleMedia.FastActionModule.FAM_SendBirthdayFlirtKey:
                    actionText = $jq("#FastActionModule" + dIndex + " .FAM_SendBirthdayFlirt");
                    actionText.css("color", "gray");
                    actionText.css("text-decoration", "none");
                    actionText.text("birthday wish sent");
                    PeopleMedia.FastActionModule.SendBirthdayFlirt(encodedMemberId, fId, dIndex, dGroup);
                    break;
            }
            if (linkUrl.length) {
                PeopleMedia.FastActionModule.ClearModuleData(PeopleMedia.FastActionModule.Actions.DisposeModule, fId, PeopleMedia.FastActionModule.FAM_ActionTaken, dIndex, dGroup, linkUrl, "href");
                PeopleMedia.FastActionModule.FAM_ActionTakenQueue[PeopleMedia.FastActionModule.FAM_ActionTakenQueue.length] = fId;
            }
        };
        this.SendFlirt = function (encodedMemberId, fId, dIndex, dGroup, sourceRecordId) {
            if (!PeopleMedia.FastActionModule.inProgress()) {
                PeopleMedia.FastActionModule.ThrottleRequest(true);
                PeopleMedia.ReloadAds();
                $jq.ajax({
                    type: 'POST',
                    url: PeopleMedia.FastActionModule.Actions.SendFlirtUrl,
                    data: {
                        EncodedMemberId: encodedMemberId,
                        FeatureName: PeopleMedia.FastActionModule.FeatureName

                    },
                    success: function (response) {
                        // Saved
                        PeopleMedia.FastActionModule.Debug(response);
                        PeopleMedia.FastActionModule.ClearModuleData(PeopleMedia.FastActionModule.Actions.DisposeModule, fId, PeopleMedia.FastActionModule.FAM_ActionTaken, dIndex, dGroup, PeopleMedia.FastActionModule.Actions.LoadModule);
                    }
                });
            }
        };
        this.SendLikePhoto = function (encodedMemberId, fId, dIndex, dGroup, sourceRecordId) {
            if (!PeopleMedia.FastActionModule.inProgress()) {
                PeopleMedia.FastActionModule.ThrottleRequest(true);
                PeopleMedia.ReloadAds();
                $jq.ajax({
                    type: 'POST',
                    url: PeopleMedia.FastActionModule.Actions.LikePhotoUrl,
                    data: {
                        EncodedMemberId: encodedMemberId,
                        ObjectId: sourceRecordId,
                        FeatureName: PeopleMedia.FastActionModule.FeatureName
                    },
                    success: function (response) {
                        // Saved
                        PeopleMedia.FastActionModule.DiposeModuleDataOnly(PeopleMedia.FastActionModule.Actions.DisposeModule, fId, PeopleMedia.FastActionModule.FAM_ActionTaken, dIndex, dGroup);
                        PeopleMedia.FastActionModule.Debug(response);
                    }
                });
            }
        };
        this.SendMessage = function (encodedMemberId, fId, dIndex, dGroup, mediaId) {
            commentText = $jq("#FastActionModule" + dIndex + " .fam_comment").val();
            if (commentText != null && commentText != 'Welcome her to the community' && commentText != 'Welcome him to the community' && commentText.length > 0) {
                $jq.ajax({
                    type: 'POST',
                    url: PeopleMedia.FastActionModule.Actions.SendMessageUrl,
                    data: {
                        EncodedMemberId: encodedMemberId,
                        Message: commentText,
                        UPN: PeopleMedia.FastActionModule.SendCommentUPN,
                        FeatureName: PeopleMedia.FastActionModule.FeatureName
                    },
                    success: function (response) {
                        // Completed
                        PeopleMedia.FastActionModule.Debug(response);
                    }
                });
                PeopleMedia.FastActionModule.ClearModuleData(PeopleMedia.FastActionModule.Actions.DisposeModule, fId, PeopleMedia.FastActionModule.FAM_ActionTaken, dIndex, dGroup, PeopleMedia.FastActionModule.Actions.LoadModule);
            } else {
                $jq("#FastActionModule" + dIndex + " .captionactionplaceholder").html("Uh Oh! Be sure to enter your comment in the box below.");
            }

        };
        this.SendCommentUpgrade = function (encodedMemberId, fId, dIndex, dGroup, mediaId) {
            document.location.href = PeopleMedia.FastActionModule.Actions.SendCommentUpgradeUrl + "?encryptedProfile=" + encodedMemberId;
        };
        this.SendComment = function (encodedMemberId, fId, dIndex, dGroup, mediaId) {
            commentText = $jq("#FastActionModule" + dIndex + " .fam_comment").val();
            if (commentText != 'What do you like about this photo?' && commentText.length > 0) {
                $jq.ajax({
                    type: 'POST',
                    url: PeopleMedia.FastActionModule.Actions.CommentPhotoUrl,
                    data: {
                        EncodedMemberId: encodedMemberId,
                        ObjectId: mediaId,
                        Message: commentText,
                        UPN: PeopleMedia.FastActionModule.SendCommentUPN,
                        FeatureName: PeopleMedia.FastActionModule.FeatureName

                    },
                    success: function (response) {
                        // Completed
                        PeopleMedia.FastActionModule.Debug(response);
                    }
                });
                PeopleMedia.FastActionModule.ClearModuleData(PeopleMedia.FastActionModule.Actions.DisposeModule, fId, PeopleMedia.FastActionModule.FAM_ActionTaken, dIndex, dGroup, PeopleMedia.FastActionModule.Actions.LoadModule);
            } else {
                $jq("#FastActionModule" + dIndex + " .captionactionplaceholder").html("Uh Oh! Be sure to enter your comment in the box below.");
            }
        };
        this.SendBirthdayFlirt = function (encodedMemberId, fId, dIndex, dGroup) {
            if (!PeopleMedia.FastActionModule.inProgress()) {
                PeopleMedia.FastActionModule.ThrottleRequest(true);
                PeopleMedia.ReloadAds();
                $jq.ajax({
                    type: 'POST',
                    url: PeopleMedia.FastActionModule.Actions.SendBirthdayFlirtUrl,
                    data: {
                        EncodedMemberId: encodedMemberId,
                        FeatureName: PeopleMedia.FastActionModule.FeatureName
                    },
                    success: function (response) {
                        // Saved
                        PeopleMedia.FastActionModule.Debug(response);
                        PeopleMedia.FastActionModule.ClearModuleData(PeopleMedia.FastActionModule.Actions.DisposeModule, fId, PeopleMedia.FastActionModule.FAM_ActionTaken, dIndex, dGroup, PeopleMedia.FastActionModule.Actions.LoadModule);
                    }
                });
            }
        };
        this.SaveToFavorites = function (encodedMemberId, fId, dIndex, dGroup) {
            if (!PeopleMedia.FastActionModule.inProgress()) {
                PeopleMedia.FastActionModule.ThrottleRequest(true);
                PeopleMedia.ReloadAds();
                $jq.ajax({
                    type: 'POST',
                    url: PeopleMedia.FastActionModule.Actions.AddFavoriteUrl,
                    data: {
                        EncodedMemberId: encodedMemberId,
                        FeatureName: PeopleMedia.FastActionModule.FeatureName
                    },
                    success: function (response) {
                        // Saved
                        PeopleMedia.FastActionModule.Debug(response);
                        PeopleMedia.FastActionModule.ClearModuleData(PeopleMedia.FastActionModule.Actions.DisposeModule, fId, PeopleMedia.FastActionModule.FAM_ActionTaken, dIndex, dGroup, PeopleMedia.FastActionModule.Actions.LoadModule);

                    }
                });
            }
        };
        this.SetModuleData = function (data, dIndex) {
			//alert("setmoduledata");		
            var hideAllModuleCheck = true;
            if (data) {
                if (data.redirect) {
                    location.href = data.redirect;
                }
                PeopleMedia.FastActionModule.Debug(data);
                if (data.status == "Success" && data.results.length > 0) {
                    hideAllModuleCheck = false;
                    for (var index in data.results) {
                        PeopleMedia.FastActionModule.SetModuleDisplayType(data.results[index]);
                    }
                } else {
                    $jq("#FastActionModule" + dIndex).html("");
                }
            }

            $jq("#famloadingbar").fadeOut();

            if (hideAllModuleCheck) {
                // make sure each one is empty before calling this
                if ($jq("#FastActionModule1").html().length == 0 && $jq("#FastActionModule2").html().length == 0 && $jq("#FastActionModule3").html().length == 0) {
                    $jq("#fastaction").hide('fast');
                }
            }
        };
        this.SetModuleDisplayType = function (details) {
            var BaseActionHtml = "";
            var EventTypeScript = "''";

            if (details.MoreNotificationsAvailable == true) {
                $jq("#NextUpdatesButton").show();
            } else if (details.MoreNotificationsAvailable == undefined) {
                // this happens in IE due to array input function at the bottom of this file
                return;
            } else {
                $jq("#NextUpdatesButton").hide();
            }

            switch (details.EventTypeId) {
                case "AddedNewProfilePhoto":
                case 1:
                case 4:
                    BaseActionHtml = $jq("#FAM-AddedNewProfilePhoto").html();
                    EventTypeScript = "PeopleMedia.FastActionModule.FAM_LikePhotoKey";
                    break;
                case "AddedNewPhoto":
                case 2:
                    BaseActionHtml = $jq("#FAM-AddedNewPhoto").html();
                    break;
                case "Birthday":
                case 3:
                    BaseActionHtml = $jq("#FAM-Birthday").html();
                    EventTypeScript = "PeopleMedia.FastActionModule.FAM_SendBirthdayFlirtKey";
                    break;
                case "NewApprovedGreeting":
                case 5:
                    BaseActionHtml = $jq("#FAM-NewApprovedGreeting").html();
                    break;
                case "Hometown":
                case 6:
                    BaseActionHtml = $jq("#FAM-Hometown").html();
                    EventTypeScript = "PeopleMedia.FastActionModule.FAM_SaveToFavoritesKey";
                    break;
                case "InterestMatch":
                case 7:
                    BaseActionHtml = $jq("#FAM-InterestMatch").html();
                    break;
                case "CompletedInterests":
                case 8:
                    BaseActionHtml = $jq("#FAM-CompletedInterests").html();
                    break;
                case "PhotoLiked3Times":
                case 9:
                    BaseActionHtml = $jq("#FAM-PhotoLiked3Times").html();
                    break;
                case "NewMemberInArea":
                case 10:
                    BaseActionHtml = $jq("#FAM-NewMemberInArea").html();
                    EventTypeScript = "PeopleMedia.FastActionModule.FAM_NewMemberInAreaKey";
                    break;
            }

            /*if (BaseActionHtml.length <= 0) {
            BaseActionHtml = "No Display for " + details.EventTypeId;
            }*/

            // Replace the filler values with real data
            BaseActionHtml = BaseActionHtml.replace(/%EventTypeScript%/g, EventTypeScript);
            BaseActionHtml = BaseActionHtml.replace(/%MemberId%/g, details.MemberId);
            BaseActionHtml = BaseActionHtml.replace(/%SourceRecordId%/g, details.SourceRecordId);
            BaseActionHtml = BaseActionHtml.replace(/%Username%/g, details.Username);
            BaseActionHtml = BaseActionHtml.replace(/%Gender%/g, details.Gender);
            BaseActionHtml = BaseActionHtml.replace(/%GenderBirthdayText%/g, details.GenderBirthdayText);
            BaseActionHtml = BaseActionHtml.replace(/%GenderSelf%/g, details.GenderSelf);
            BaseActionHtml = BaseActionHtml.replace(/%DisplayIndex%/g, details.DisplayIndex);
            BaseActionHtml = BaseActionHtml.replace(/%DisplayGroup%/g, details.DisplayGroup);
            BaseActionHtml = BaseActionHtml.replace(/%EventTypeId%/g, details.EventTypeId);
            BaseActionHtml = BaseActionHtml.replace(/%fId%/g, details.FastActionNotificationId);
            BaseActionHtml = BaseActionHtml.replace(/%EncodedMemberId%/g, details.EncodedMemberId);

            // special replaces for links to avoid 404 errors
            BaseActionHtml = BaseActionHtml.replace(/\?%ProfilePhotoUrl%/g, details.ProfilePhotoUrl);
            BaseActionHtml = BaseActionHtml.replace(/\?%ProfileUrl%/g, details.ProfileUrl);
            BaseActionHtml = BaseActionHtml.replace(/\?%ActionUrl%/g, details.ActionUrl);
            BaseActionHtml = BaseActionHtml.replace(/tellherbtn/g, "tell" + details.Gender + "btn");

            // Load the module in the correct spot
            $jq("#FastActionModule" + details.DisplayIndex).fadeOut("slow", function () {
                $jq("#FastActionModule" + details.DisplayIndex).html(BaseActionHtml);
                $jq("#FastActionModule" + details.DisplayIndex + " .profileimageclass").attr('src', details.ProfilePhotoUrl);
                $jq("#FastActionModule" + details.DisplayIndex + " .FAM_LikePhoto").hover(
                  function () {
                      $jq("#FastActionModule" + details.DisplayIndex + " .FAM_LikePhotoHover").show();
                  },
                  function () {
                      $jq("#FastActionModule" + details.DisplayIndex + " .FAM_LikePhotoHover").hide();
                  }
              );
                $jq("#FastActionModule" + details.DisplayIndex).fadeIn("fast");
            });
            $jq("#FastActionModule" + details.DisplayIndex).hover(
             function () {
                 $jq("#" + details.DisplayIndex).show();
             },
             function () {
                 $jq("#closebutton" + details.DisplayIndex).hide();
             }
			);

        };
    };

// note: to support IE indexOf for queueing system
if (!Array.prototype.indexOf)
 {
   Array.prototype.indexOf = function(elt /*, from*/)
   {
     var len = this.length >>> 0;
     var from = Number(arguments[1]) || 0;
     from = (from < 0) ? Math.ceil(from) : Math.floor(from);
     if (from < 0) from += len;
     for (; from < len; from++){if (from in this && this[from] === elt)return from;}
     return -1;
   };
 }
